home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
dev
/
c
/
MemPools.readme
< prev
next >
Wrap
Text File
|
1994-12-18
|
7KB
|
176 lines
Short: Malloc() replacement using Exec pools
Author: jochen.wiedmann@uni-tuebingen.de
Uploader: jochen.wiedmann@uni-tuebingen.de
Type: dev/c
MemPools - malloc() replacement using standard Exec memory pools
================================================================
Many people don't like using malloc() and similar functions because
they think it's too slow and gives too much overhead. Well, as far as
I can say they're alright, at least for users of Dice and SAS/C:
the Exec pool functions seem to be at least 5 times faster and it
can even be faster than the malloc() of GNU-c! (See "Timings" below.)
Other people like malloc(): It's portable and rather easy to use.
I am one of these, however I don't want to loose the speed of
pool functions.
The mempools package is a link library with the functions malloc(),
calloc(), realloc(), strdup() and free(). It replaces the compilers
own functions by just linking against this library. No additional
work is required as the library takes use of the compilers auto-
initialization facility.
Ths autoinitialization restricts use of the mempools library to
users of Dice, SAS/C and gcc: I don't know how to handle other
compilers.
Note, that pools are available not only for users of OS 3.x! The
current amiga.lib offers replacements which call exec.library,
if the OS is 3.x and emulate pools otherwise. The MemPools
library uses this replacements.
1.) Disclaimer: Copyrights, (No) Warranty
-----------------------------------------
This program is Copyright (C) 1994 Jochen Wiedmann
Am Eisteich 9
72555 Metzingen
Germany
Phone: (0049) +7123 / 14881
Mail: jochen.wiedmann@uni-tuebingen.de
Permission is granted to make and distribute either verbatim and modified
copies of this documentation and the library MemPools provided the copyright
notice and this permission notice are preserved on all copies and the "GNU
General Public License" (in the file COPYING) is distributed as well.
The author gives ABSOLUTELY NO warranty that the software described in this
documentation and the results produced by them are correct. The author
cannot be held responsible for ANY damage resulting from the use of this
software.
2.) Installation
----------------
There are four libraries included in the distribution, it depends
on your compiler which one you need: mempoolss.lib and mempoolssr.lib
are for dice, they should be copied to DLIB: or a similar place.
mempools.lib is for SAS/C, its destination is sc:lib. Finally
libmempools.a is the GNU-c version which should go to GNU:lib.
If you want to recreate them, just type smake (SAS/C) or make (GNU-c).
Dice, however, requires different libraries, depending on the data
model, the type of argument handling and so on.
To create a certain library just type
lbmake mempools s (for mempoolss.lib)
lbmake mempools s r (for mempoolssr.lib)
lbmake mempools l (for mempoolsl.lib)
.
.
.
3.) Usage
---------
All you have to do is to link against the mempools library.
a) Dice
Add the option -lmempools to your compiler statement. By adding
it to the environment variable "DCCOPTS" you get this automatically.
b) SAS/C
Add the option LIB mempools to your compiler statement. By using
the "scopts" program you can get this automatically, too.
c) gcc
Add the option -lmempools to your compiler statement. I don't know
if gcc can handle this automatically. Probably someone can
enlighten me?
However, you might be interested in controlling the pools attributes.
This can be done by creating global variables __MemPoolPuddleSize,
__MemPoolThreshSize and __MemPoolFlags which correspond to the
arguments of the CreatePool() function. For example, if you want
to modify the puddle size (this can increase speed, see "Timings"
below), just add the following line somewhere to your program:
ULONG __MemPoolPuddleSize = 16384; /* Default: 4096 */
Or if you want malloc() to obtain chip memory, just write
#include <exec/memory.h>
ULONG __MemPoolFlags = MEMF_CHIP; /* Default: MEMF_ANY */
4.) Timings
-----------
I wrote a little timing program. (I don't claim that it is very good,
probably someone can write a better one.) I was rather surprised about
the results:
Compiler Time (Mins:Secs) Notes
Dice 2:46,74 Dice maps malloc() to AllocMem()
directly. This is extremely poor!
Especially the exit() function
needs about 20% of the programs
time.
SAS/C 1:17,66 SAS/C uses an own pool system.
Thus the exit() function is
rather fast. malloc(), however,
seems to be slow.
gcc 0:12,84 (ixemul) gcc uses a pool system which is
0:14,34 (libnix) rather close to Exec pools. This
gives good results.
MemPools 0:15,10 (4096) By increasing the puddle size
0:12,14 (8192) (see "Usage") you get better
0:10,80 (16384) results! It seems worth to ry a
little bit.
============================= Archive contents =============================
Original Packed Ratio Date Time Name
-------- ------- ----- --------- -------- -------------
1693 904 46.6% 04-Dec-94 21:16:28 mempools/calloc.c
17982 6993 61.1% 01-Sep-93 18:40:30 mempools/COPYING
3051 1224 59.8% 05-Dec-94 04:27:36 mempools/DMakefile
1519 836 44.9% 04-Dec-94 18:22:16 mempools/free.c
2727 1229 54.9% 04-Dec-94 18:39:32 mempools/init.c
1337 572 57.2% 05-Dec-94 03:27:22 mempools/lib.def
3294 1059 67.8% 06-Dec-94 00:47:26 mempools/libmempools.a
2893 1163 59.7% 05-Dec-94 03:28:12 mempools/Makefile
1596 868 45.6% 04-Dec-94 21:24:48 mempools/malloc.c
59 59 0.0% 04-Dec-94 18:42:08 mempools/MemPoolFlags.c
60 60 0.0% 04-Dec-94 18:40:54 mempools/MemPoolPuddleSize.c
1916 828 56.7% 06-Dec-94 00:43:16 mempools/mempools.lib
5016 2246 55.2% 06-Dec-94 00:41:30 mempools/MemPools.readme
2688 985 63.3% 06-Dec-94 00:42:00 mempools/mempoolss.lib
2628 958 63.5% 06-Dec-94 00:42:40 mempools/mempoolssr.lib
59 59 0.0% 04-Dec-94 20:09:24 mempools/MemPoolThreshSize.c
1689 872 48.3% 04-Dec-94 21:15:56 mempools/realloc.c
2862 1164 59.3% 05-Dec-94 03:27:46 mempools/SMakefile
1491 819 45.0% 05-Dec-94 04:13:30 mempools/strdup.c
4480 1653 63.1% 05-Dec-94 03:50:44 mempools/TimeMem.c
2861 1308 54.2% 05-Dec-94 01:32:44 mempools/TimeProg.c
-------- ------- ----- --------- --------
61901 25859 58.2% 07-Dec-94 18:33:10 21 files